package com.atguigu.educms.service.impl;

import com.atguigu.educms.entity.CmsBanner;
import com.atguigu.educms.mapper.CmsBannerMapper;
import com.atguigu.educms.service.CmsBannerService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-06-23
 */
@Service
public class CmsBannerServiceImpl extends ServiceImpl<CmsBannerMapper, CmsBanner> implements CmsBannerService {
    /**
     * @Cacheable 该注解不能标注在controller的方法，而是要标注在service的方法
     *              最终数据的key就是 banners::bannerList
     * @return
     */
    @Override
    @Cacheable(key = "'banners'",value = "bannerList")
    public List<CmsBanner> getAllBannner() {
        //根据id降序排列，查询出两条记录
        QueryWrapper<CmsBanner> queryWrapper=new QueryWrapper<>();
        queryWrapper.orderByDesc("id").last("limit 2");
        List<CmsBanner> list = baseMapper.selectList(queryWrapper);
        return list;
    }
}
